/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BuscarEstudiante.java
 *
 * Created on 17/02/2011, 01:06:16 PM
 */
package Pantallas;

import Clases.Estudiante;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Reinaldo Carvallo
 */
public class BuscarEstudiante extends javax.swing.JFrame {

    /** Creates new form BuscarEstudiante */
    public BuscarEstudiante() {
        initComponents();
        txtNombreApe.setVisible(false);
        lblNombreApe.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtCedEstud = new javax.swing.JTextField();
        btnbuscar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        lblNombreApe = new javax.swing.JLabel();
        txtNombreApe = new javax.swing.JTextField();
        btnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setText("Buscar Estudiante por Cedula");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(180, 30, 180, 30);
        getContentPane().add(txtCedEstud);
        txtCedEstud.setBounds(180, 90, 200, 19);

        btnbuscar.setText("Buscar Estudiante");
        btnbuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnbuscarActionPerformed(evt);
            }
        });
        getContentPane().add(btnbuscar);
        btnbuscar.setBounds(70, 240, 160, 23);

        jLabel2.setText("Cedula del Estudiante ");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(50, 90, 140, 20);

        lblNombreApe.setText("Nombre y Apellido");
        getContentPane().add(lblNombreApe);
        lblNombreApe.setBounds(50, 150, 120, 14);
        getContentPane().add(txtNombreApe);
        txtNombreApe.setBounds(180, 150, 270, 19);

        btnSalir.setText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });
        getContentPane().add(btnSalir);
        btnSalir.setBounds(280, 240, 130, 23);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-500)/2, (screenSize.height-360)/2, 500, 360);
    }// </editor-fold>//GEN-END:initComponents

    private void btnbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbuscarActionPerformed
        // TODO add your handling code here:
        int encontrado = 0;
        if (txtCedEstud.getText().equals("")) {
            JOptionPane.showMessageDialog(new JFrame(), " Introduzca la cedula del estudiante ", "Aviso", JOptionPane.CANCEL_OPTION);
        } else {

            encontrado = MenuPrincipal.s1.Buscar(txtCedEstud.getText());
            if (encontrado == -99) {
                JOptionPane.showMessageDialog(new JFrame(), " No Se Encontro el Estudiante !!!!  ", "Aviso", JOptionPane.CANCEL_OPTION);
            } else {

                Estudiante e = (Estudiante) MenuPrincipal.s1.getEstudiantes().get(encontrado);
                txtCedEstud.setText("");
                txtNombreApe.setVisible(true);
                lblNombreApe.setVisible(true);
                txtNombreApe.setText(e.getNombre_apellido());
                
            }





        }


    }//GEN-LAST:event_btnbuscarActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_btnSalirActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new BuscarEstudiante().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSalir;
    private javax.swing.JButton btnbuscar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel lblNombreApe;
    private javax.swing.JTextField txtCedEstud;
    private javax.swing.JTextField txtNombreApe;
    // End of variables declaration//GEN-END:variables
}

